package fun.asgc.boot.netty.context;

import fun.asgc.boot.netty.annotation.Autowired;
import fun.asgc.boot.netty.annotation.Component;
import fun.asgc.boot.netty.annotation.NonIntercept;
import fun.asgc.boot.netty.bean.factory.SimpleBeanFactory;
import fun.asgc.boot.netty.web.context.WebApplicationContext;
import fun.asgc.boot.netty.web.context.WebContextHolder;

/**
 *
 * @author: aoshiguchen
 * @date: 2022/7/9
 */
@NonIntercept
@Component
public class ExtensionServiceLoader implements ApplicationRunner {
	@Autowired
	private ApplicationConfig applicationConfig;
	@Autowired
	private SimpleBeanFactory applicationBeanFactory;
	@Autowired
	private Environment environment;

	@Override
	public void run(String[] args) {
		startHttpServer();
	}

	private void startHttpServer() {
		if (null == applicationConfig) {
			return;
		}
		ApplicationConfig.Http http = applicationConfig.getHttp();
		if (null == http || null == http.getEnable() || !http.getEnable()) {
			return;
		}
		applicationBeanFactory.registerBean(WebContextHolder.class);
		applicationBeanFactory.registerBean(WebApplicationContext.class);
	}
}
